<?php

namespace app\api\controller\v1;

use app\common\controller\Api;
use think\Db;

class TeachOffline extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function index()
    {
        $scopeType = $this->request->get('scope_type', 'city');
        $scopeId = $this->request->get('scope_id');
        $regionMode = $this->request->get('region_mode', 'self');
        $summaryItems = explode(',', $this->request->get('summary_items', 'school,class,people,lessons,checkin,leave,evaluation'));
        try {
            $data = [];
            if (in_array('school', $summaryItems)) $data['school'] = Db::name('eb_school')->where('status', 1)->count();
            if (in_array('class', $summaryItems)) $data['class'] = Db::name('eb_classes')->where('status', 1)->where('teach_mode', 'offline')->count();
            if (in_array('people', $summaryItems)) $data['people'] = Db::name('eb_class_student')->where('status', 1)->where('learn_mode', 'offline')->count();
            if (in_array('lessons', $summaryItems)) $data['lessons'] = Db::name('course_lesson')->where('status', 1)->where('teach_mode', 'offline')->count();
            if (in_array('checkin', $summaryItems)) $data['checkin'] = Db::name('course_attendance')->where('status', 1)->count();
            if (in_array('leave', $summaryItems)) $data['leave'] = Db::name('course_leave')->where('status', 1)->count();
            if (in_array('evaluation', $summaryItems)) $data['evaluation'] = Db::name('course_evaluation')->where('status', 1)->count();
            return json(['code' => 200, 'msg' => 'OK', 'data' => $data]);
        } catch (\Exception $e) {
            return json(['code' => 500, 'msg' => $e->getMessage(), 'data' => []]);
        }
    }
}